﻿var SERVICE_URL = "http://localhost:1237/LogisticsService.svc/";
var giaMotKg = 0;
var sokm;
var tongtien = 1;
var gtri;
$(document).ready(function () {
    // Add the page method call as an onclick handler for the div.	       	            
    $.get(SERVICE_URL + "dsloaivanchuyen", LoadDuLieuComboboxLoaiVanChuyen);
    $.get(SERVICE_URL + "dsdiadiem", LoadDuLieuComboboxNoiGoi);
    $.get(SERVICE_URL + "dsdiadiem", LoadDuLieuComboboxNoiDen);

    CbChange();
    CbNoiDenChange();
    $(function () {
        $("#btnThanhToan").click(function () {

            //alert(document.getElementById("ctl00_cph_content_txtDCLayHang").val());
//            if (KiemTraDuLieuNhap() == true) {
                alert('Thanh Toan');
//                return false;
//            } else {
//                alert('That bai');
//            }
        });
    });
});
//function KiemTraDuLieuNhap() {
//    if (document.getElementById("ctl00_cph_content_txtDCLayHang").val() == "") {
//        $("#ctl00_cph_content_txtDCLayHang").focus();
//        $("#ctl00_cph_content_txtDCLayHang").style.background = 'Yellow';
//        alert("Fullname can not empty!");
//        return false;
//    }
////    soNha = document.getElementById("textboxSoNha").value;
////    tenDuong = document.getElementById("textboxTenDuong").value;
////    phuongXa = document.getElementById("textboxTenPhuongXa").value;
////    quanHuyen = document.getElementById("textboxTenQuanHuyen").value;
////    viDo = document.getElementById("textboxViDo").value;
////    kinhDo = document.getElementById("textboxKinhDo").value;

////    if (tenDuong == "" || tenNhaTro == "" || soNha == "" || phuongXa == "" || quanHuyen == "" || viDo == "" || kinhDo == "")
////        return false;

//    return true;
//}
function TimKm(data) {
    if (data == 0) {
        tongtien = 0;
        alert('Không tồn tại tuyến đường đã chọn');
    }
    else {
        sokm = data;
        //alert("So km" + sokm);
        $.get(SERVICE_URL + "banggia/" + sokm, GiakgTheoSoKm);

    }
}
function GiakgTheoSoKm(banggia) {
    //alert(banggia[0].Ma);
    // alert("So km" + sokm);
    var len = banggia.length;
    //alert("length" + len);
    //tim gia gan km nhat
    for (i = 0; i < len; i++) {
        if (banggia[i].SoKiLoMet > sokm) {
            giaMotKg = banggia[i].GiaMotKg;
            break;
        }
    }
    //alert(giaMotKg);
}
function LoadDuLieuComboboxLoaiVanChuyen(data) {
    var len = data.length;
<<<<<<< .mine    var select = document.getElementById("ddlLoaiVanChuyen");
=======    var select = document.getElementById("ctl00_cph_content_ddlLoaiVanChuyen");
>>>>>>> .theirs    //Binding vao select
    for (var i = 0; i < len; i++) {
        var lvc = data[i];

        var optn = document.createElement("OPTION");
        optn.text = lvc.Ten;
        optn.value = lvc.Ma;

        select.options.add(optn);
    }
}
function LoadDuLieuComboboxNoiGoi(data) {
    var len = data.length;
    var sel = document.getElementById("ddlNoiGoi");
    //Binding vao select
    for (var i = 0; i < len; i++) {
        var chinhanh = data[i];

        var optn = document.createElement("OPTION");
        optn.text = chinhanh.Ten;
        optn.value = chinhanh.Ma;

        sel.options.add(optn);
    }
}

function LoadDuLieuComboboxNoiDen(data) {
    var len = data.length;
    var sel = document.getElementById("ddlNoiDen");
    //Binding vao select
    for (var i = 0; i < len; i++) {
        var chinhanh = data[i];

        var optn = document.createElement("OPTION");
        optn.text = chinhanh.Ten;
        optn.value = chinhanh.Ma;

        sel.options.add(optn);
    }
}
<<<<<<< .minefunction CbChange() {
    $("#ddlLoaiVanChuyen").change(function () {

        gtri = $("#ddlLoaiVanChuyen").val();
        var diemdau = $("#ddlNoiGoi").val();
        var diemcuoi = $("#ddlNoiDen").val();
        $.get(SERVICE_URL + "timsokm" + "/" + diemdau + "/" + diemcuoi, TimKm); //tinh so km
        //alert("gtri "+gtri);
        if (gtri == "LVC0000001") {
            //alert("tongtientruoc" + tongtien);
            tongtien = sokm * giaMotKg * 3;
            //alert("tongtien" + tongtien);
        }
        if (gtri == "LVC0000002") {
            tongtien = sokm * giaMotKg * 2;
        }
        if (gtri == "LVC0000003") {
            tongtien = sokm * giaMotKg * 1;
        }
        $("#tongtien").show().html('Tổng tiền:');

        $("#gia").show().html(tongtien);
=======function CbChange() {
    $("#ctl00_cph_content_ddlLoaiVanChuyen").change(function () {

        gtri = $("#ctl00_cph_content_ddlLoaiVanChuyen").val();
        var diemdau = $("#ctl00_cph_content_ddlNoiGoi").val();
        var diemcuoi = $("#ctl00_cph_content_ddlNoiDen").val();
        $.get(SERVICE_URL + "timsokm" + "/" + diemdau + "/" + diemcuoi, TimKm); //tinh so km
        //alert("gtri "+gtri);
        if (gtri == "LVC0000001") {
            //alert("tongtientruoc" + tongtien);
            tongtien = sokm * giaMotKg * 3;
            //alert("tongtien" + tongtien);
        }
        if (gtri == "LVC0000002") {
            tongtien = sokm * giaMotKg * 2;
        }
        if (gtri == "LVC0000003") {
            tongtien = sokm * giaMotKg * 1;
        }
        $("#tongtien").show().html('Tổng tiền:');

        $("#gia").show().html(tongtien);
    });
}

$(function () {
    $("#btnThanhToan").click(function () {
        alert('Thanh Toan');
        window.location(http://localhost:2370/lotrinh.aspx")
>>>>>>> .theirs    });
<<<<<<< .mine}

function CbNoiDenChange() {
    $("#ddlNoiDen").change(function () {

        gtri = $("#ddlLoaiVanChuyen").val();
        var diemdau = $("#ddlNoiGoi").val();
        var diemcuoi = $("#ddlNoiDen").val();
        $.get(SERVICE_URL + "timsokm" + "/" + diemdau + "/" + diemcuoi, TimKm); //tinh so km
        //alert("gtri "+gtri);
        if (gtri == "LVC0000001") {
            //alert("tongtientruoc" + tongtien);
            tongtien = sokm * giaMotKg * 3;
            //alert("tongtien" + tongtien);
        } else {
            if (gtri == "LVC0000002") {
                tongtien = sokm * giaMotKg * 2;
            } else {
                if (gtri == "LVC0000003") {
                    tongtien = sokm * giaMotKg * 1;
                }
            }
        }
        $("#tongtien").show().html('Tổng tiền:');

        $("#gia").show().html(tongtien);
    });
}

=======});
>>>>>>> .theirs